home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Plotting / aa_Intel_Only / Gnuplot / GnuplotSource / ContourUserPane.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  4.6 KB  |  225 lines

  1. /*
  2.  *  Copyright (C) 1993  Robert Davis
  3.  *
  4.  *  This program is free software; you can redistribute it and/or
  5.  *  modify it under the terms of Version 2, or any later version, of 
  6.  *  the GNU General Public License as published by the Free Software 
  7.  *  Foundation.
  8.  */
  9.  
  10.  
  11. static char RCSId[]="$Id: ContourUserPane.m,v 1.2 1993/05/04 16:21:30 davis Exp $";
  12.  
  13. #import <appkit/Application.h>
  14. #import <appkit/publicWraps.h>        /* NXBeep() */
  15. #import <appkit/TextField.h>
  16.  
  17. #import "CellScrollView.h"
  18. #import "ContourUserPane.h"
  19. #import "DoubleObject.h"
  20. #import "DoubleValueSortedList.h"
  21. #import "EditMatrix.h"
  22. #import "Status.h"
  23. #import "StatusContour.h"
  24. #import "SubCell.h"
  25.  
  26.  
  27. @interface ContourUserPane (Private)
  28. - _updateControlsForSelectedLevel;
  29. @end
  30.  
  31.  
  32.  
  33. @implementation ContourUserPane
  34.  
  35. - init
  36. {
  37.     [super init];
  38.  
  39.     [NXApp loadNibSection: "ContourUserPane.nib"
  40.             owner: self
  41.         withNames: NO
  42.          fromZone: [self zone]];
  43.  
  44.     /*  Setup the scroll view  */
  45.  
  46.     [scrollView initMatrixCellClass:[SubCell class] cols:1];
  47.     levelsMatrix = [scrollView cellMatrix];
  48.     [[levelsMatrix setAction:@selector(selectLevel:)] setTarget:self];
  49.  
  50.     return self;
  51. }
  52.  
  53.  
  54. - (BOOL)updateStatus:aStatus doc:aDoc
  55. {
  56.     BOOL    isEnabled;
  57.  
  58.     if ([super updateStatus:aStatus doc:aDoc]) {
  59.  
  60.     levelsList = [status levelDefs];
  61.     [scrollView loadCol:0 from:levelsList];
  62.  
  63.     } else
  64.     [scrollView loadCol:0 from:nil];
  65.  
  66.     [self selectLevel:self];
  67.     [addButton setEnabled:isEnabled = [doc isEnabled]];
  68.     [valueField setEnabled:isEnabled];
  69.     [valueFieldTitle setEnabled:isEnabled];
  70.     [levelsMatrix setEnabled:isEnabled];
  71.     [deleteButton setEnabled:isEnabled = (isEnabled
  72.                       && [levelsMatrix selectedCell])];
  73.     [modifyButton setEnabled:isEnabled];
  74.  
  75.     return YES;
  76. }
  77.  
  78.  
  79. - add:sender
  80. {
  81.     DoubleObject    *doubleObject;
  82.     int        location;
  83.     BOOL    changed = YES;
  84.  
  85.     doubleObject = [[DoubleObject allocFromZone:[status zone]]
  86.                  initFromDouble:[valueField doubleValue]];
  87.     location = [levelsList addObjectIfDoubleAbsent:doubleObject];
  88.  
  89.     if (location == NX_NOT_IN_LIST) {
  90.     [doubleObject free];
  91.     location = [levelsMatrix selectedRow];
  92.     changed = NO;
  93.     NXBeep();
  94.     }
  95.  
  96.     [scrollView loadCol:0 from:levelsList];
  97.     [levelsMatrix scrollCellToVisible:location :0];
  98.     [levelsMatrix selectCellAt:location :0];
  99.  
  100.     [self selectLevel:self];
  101.     if (changed)
  102.     [status reportSettingsChange:self];
  103.  
  104.     return self;
  105. }
  106.  
  107.  
  108. - modify:sender
  109. {
  110.     DoubleObject    *dobj = [[levelsMatrix selectedCell] subObject];
  111.     int            location;
  112.  
  113.     [dobj setDoubleValue:[valueField doubleValue]];
  114.  
  115.     /*  
  116.      *  Remove the level from the list and reinsert it,
  117.      *  to maintain the sort order of the list.
  118.      */
  119.     location = [levelsList addObject:[levelsList removeObject:dobj]];
  120.     [scrollView loadCol:0 from:levelsList];
  121.     [levelsMatrix scrollCellToVisible:location: 0];
  122.     [levelsMatrix selectCellAt:location :0];
  123.     [self selectLevel:self];
  124.  
  125.     [status reportSettingsChange:self];
  126.     return self;
  127. }
  128.  
  129.  
  130.  
  131. - delete:sender
  132. {
  133.     int        i;
  134.     int        maxrow = [levelsMatrix cellCount] - 1;
  135.     int        row = maxrow;
  136.     BOOL    gotRow = NO;
  137.  
  138.     for (i = maxrow; i >= 0; i--) {
  139.     SubCell    *cell = [levelsMatrix cellAt:i:0];
  140.  
  141.     if ([cell isHighlighted]) {
  142.         /*
  143.          *  If a cell is highlighted, remove (and free) the
  144.          *  corresponding item from the list of DoubleObjects.
  145.          */
  146.         [[levelsList removeObject:[cell subObject]] free];
  147.  
  148.         if (!gotRow) {
  149.         row = (i == maxrow)? i - 1 :i;
  150.         gotRow = YES;
  151.         } else
  152.         row--;
  153.     }
  154.     }
  155.  
  156.     [scrollView loadCol:0 from:levelsList];
  157.  
  158.     [levelsMatrix selectCellAt:row :0];
  159.     [levelsMatrix scrollCellToVisible:row :0];
  160.     [self selectLevel:self];
  161.  
  162.     if (gotRow)        /* gotRow will be YES if any cells were deleted */
  163.     [status reportSettingsChange:self];
  164.  
  165.     return self;
  166. }
  167.  
  168.  
  169.  
  170. /*  
  171.  *  Selects a level if none is selected and then updates the controls 
  172.  *  based on the selected level.
  173.  */
  174. - selectLevel:sender
  175. {
  176.     if (![levelsMatrix selectedCell]
  177.     && ![levelsMatrix multipleCellsSelected]) {
  178.  
  179.     [levelsMatrix selectCellAt:0:0];
  180.  
  181.     }
  182.  
  183.     [self _updateControlsForSelectedLevel];
  184.     return self;
  185. }
  186.  
  187.  
  188. // Shuts up the compiler about unused RCSId
  189. - (const char *) rcsid
  190. {
  191.     return RCSId;
  192. }
  193.  
  194.  
  195. @end
  196.  
  197.  
  198.  
  199. @implementation ContourUserPane (Private)
  200.  
  201. - _updateControlsForSelectedLevel
  202. {
  203.     SubCell    *singleCell = [levelsMatrix selectedCell];
  204.     BOOL    enabled = (singleCell || [levelsMatrix multipleCellsSelected]);
  205.  
  206.     if (singleCell) {
  207.     DoubleObject *dobj = [singleCell subObject];
  208.  
  209.     [valueField setDoubleValue:[dobj doubleValue]];
  210.  
  211.     } else {
  212.  
  213.     [valueField setStringValue:""];
  214.     }
  215.  
  216.     [deleteButton setEnabled:enabled];
  217.     [modifyButton setEnabled:singleCell? YES:NO];
  218.     [valueField selectText:self];
  219.  
  220.     return self;
  221. }
  222.  
  223.  
  224. @end
  225.